﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>中小学入转学管理系统</title>
    <link href="~/Content/css/framework-font.css" rel="stylesheet" />
    <link href="~/Content/css/framework-login.css" rel="stylesheet" />
    <script src="~/Content/js/jquery/jquery-2.1.1.min.js"></script>
    <script src="~/Content/js/cookie/jquery.cookie.js"></script>
    <script src="~/Content/js/md5/jquery.md5.js"></script>
    <script src="~/Content/js/bootstrap/bootstrap.js"></script>
    <link href="~/Content/js/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <script src="~/Content/js/bootbox.js"></script>
    <!--[if lte IE 8]>
        <div id="errorie"><div>您还在使用老掉牙的IE，正常使用系统前请升级您的浏览器到 IE8以上版本 <a target="_blank" href="http://windows.microsoft.com/zh-cn/internet-explorer/ie-8-worldwide-languages">点击升级</a>&nbsp;&nbsp;强烈建议您更改换浏览器：<a href="http://down.tech.sina.com.cn/content/40975.html" target="_blank">谷歌 Chrome</a></div></div>
    <![endif]-->
    <style>
        .head_container {
            max-width: 400px;
            margin: 0 auto;
            text-align: center;
            position: relative;
            margin-top: 150px;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="head_container">
            <div class="logo">
                <h1 style="font-size:25px;color:#fff">中小学转学网上申请系统</h1>
            </div>
            <form class="form">
                <div class="row">
                    <input id="txtMobile" type="text" placeholder="手机号">
                    <i class="fa fa-user"></i>
                </div>
                <div class="row">
                </div>
                <div class="row">
                    <div style="width: 110px; float: left; padding-top: 14px;">
                    <input id="txtVerifyCode" maxlength="6" type="text" placeholder="验证码" style="width: 110px; float: left;">
                        </div>
                    <div style="width: 110px; float: left; padding-top: 14px; padding-left: 35px;">
                        <button id="verifyCode" type="button" onclick="getVerifyCode()" style="width:150px"><span>验证码</span></button>
                    </div>
                </div>
                <div class="row">
                    <input id="newPwd" type="password" placeholder="密码">
                    <i class="fa fa-key"></i>
                </div>
                <div class="row">
                    <input id="confirmNewPwd" type="password" placeholder="重复密码">
                    <i class="fa fa-key"></i>
                </div>
                <input id="keyValue" type="hidden" value="@ViewBag.keyValue">
                <div class="row">
                    <button id="btn_add" type="button" onclick="btn_register()"><span>注册</span></button>
                </div>
                <div class="row">
                </div>
            </form>
        </div>
        </div>
    <div class="copyright">
        <a href="" style="text-decoration:none;color:#fff;">威海市文登区教育和体育局</a>
        <br>
       
    </div>
    <script type="text/javascript">
        (function ($) {
            var keyValue = $('#keyValue').val();
            if ('2' == keyValue) {
                $("#btn_add").find('span').html("重置密码");
            }

            $.login = {
                init: function () {
                    $('.wrapper').height($(window).height());
                    $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    $(window).resize(function (e) {
                        $('.wrapper').height($(window).height());
                        $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
                    });
                }
            };
            $(function () {
                $.login.init();
            });
        })(jQuery);

        function checkMobile(s) {
            var regu = /^[1][0-9]{10}$/;
            var re = new RegExp(regu);
            if (re.test(s)) {
                return true;
            } else {
                return false;
            }
        }

        function getVerifyCode() {
            var mobile = $("#txtMobile").val();
            if (!checkMobile(mobile)) {
                    bootbox.alert('手机号格式不正确，请重新输入！');
                return;
            }

            $.ajax({
                url: "/Login/GetVerifyCode",
                data: { mobile: mobile },
                type: "post",
                dataType: "json",
                async: false,
                success: function (data) {
                    console.log(data);
                    if (data.state == 'success') {
                        MyTime();
                    }
                    if (data.state == 'error') {
                        bootbox.alert(data.message);
                        return;
                    }
                }
            });
        }

        var wait = 120;
        function MyTime() {
            if (wait == 0) {
                $("#verifyCode").removeAttr("disabled"); 
                $("#verifyCode").css('background-color', '#1ABC9C'); 
                $("#verifyCode").find('span').html("验证码");
                wait = 120;
            } else {
                $("#verifyCode").attr("disabled", true);
                $("#verifyCode").css('background-color', 'aquamarine'); 
                var tempStr = "重新发送(" + wait + ")";
                $("#verifyCode").find('span').html(tempStr);
                wait--;
                setTimeout(function () {
                    MyTime()
                },1000)
            }
        }

        function btn_register() {
            var txtMobile = $('#txtMobile').val();
            var txtVerifyCode = $('#txtVerifyCode').val();
            var newPwd = $('#newPwd').val();
            var confirmNewPwd = $('#confirmNewPwd').val();
            var keyValue = $('#keyValue').val();
            console.log(keyValue);
            if ('' == txtMobile || null == txtMobile) {
                bootbox.alert('手机号不能为空，请重新输入！');
                return;
            }
            if ('' == txtVerifyCode || null == txtVerifyCode) {
                bootbox.alert('验证码不能为空，请重新输入！');
                return;
            }
            if ('' == newPwd || null == newPwd) {
                bootbox.alert('密码不能为空，请重新输入！');
                return;
            }
            if ('' == newPwd || null == newPwd) {
                bootbox.alert('密码不能为空，请重新输入！');
                return;
            }
            if ('' == confirmNewPwd || null == confirmNewPwd) {
                bootbox.alert('重复密码不能为空，请重新输入！');
                return;
            }
            if (newPwd != confirmNewPwd) {
                bootbox.alert('新密码前后输入不一致,请重新输入！');
                return;
            }
            $.ajax({
                url: "/Login/register",
                data: { txtMobile: txtMobile, txtVerifyCode: txtVerifyCode, newPwd: newPwd, keyValue: keyValue},
                type: "post",
                dataType: "json",
                success: function (data) {
                    console.log(data.state);
                    if (data.state == 'success') {
                        alert(data.message);
                        window.location.href = "/Login/Index";
                        return false;
                    } else {
                        alert(data.message);
                        return;
                    }
                }
            });
        }
    </script>
</body>
</html>
